package com.base.util;



import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;



/**
 * 用于启动Spring的公用类
 */
public class SpringUtils {
	protected static Log logger = LogFactory.getLog(SpringUtils.class);
	
	private ApplicationContext applicationContext;
	private static final SpringUtils manager = new SpringUtils();  
	
	
	private SpringUtils(){
			init();
	}
	
	public static SpringUtils getInstance(){
		return manager;
	}
	
	private void init(){
		try{
			applicationContext = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/context/Context-dao.xml");
			logger.info("load Spring sucess!***************************************************");
		}catch(Exception e){
			e.printStackTrace();
			logger.error("load spring error!" + e);
		}
	}
	
	
	public Object getBean(String beanName){
		return applicationContext.getBean(beanName);
	}
}
